<?php
declare (strict_types = 1);

namespace app\model;

use think\Model;

/**
 * @mixin \think\Model
 */
class Cat extends Model
{
    //
    //id搜索器
    public function searchIdAttr($query, $value)
    {
        return $value ? $query->where('id', $value) : '';
    }

    //name搜索器
    public function searchNameAttr($query, $value)
    {
        return $value ? $query->where('name',$value) : '';
    }
    //url搜索器
    public function searchUrlAttr($query, $value)
    {
        return $value ? $query->where('url', $value) : '';
    }

    //img获取器
    public function getImgAttr( $value)
    {
        return $value ? request()->domain().'/static/'.$value : '';
    }

    //create_time搜索器
    public function searchCreateAtAttr($query, $value)
    {
        return $value ? $query->order('create_at', $value) : '';
    }
    public function adv(){
        return $this->hasMany(Adv::class,'cat_id');
    }
    public function info(){
        return $this->hasOne(Info::class,'cat_id');
    }
}

